package utils

import (
	"encoding/csv"
	"os"
)

func ExportFile(data [][]string) (filename string, err error) {
	// 创建文件
	filename = "export.csv"
	if newFile, err := os.Create(filename); err != nil {
		return filename, err
	} else {
		defer func() {
			newFile.Close()
		}()
		// 写入UTF-8
		newFile.WriteString("\xEF\xBB\xBF") // 写入UTF-8 BOM，防止中文乱码
		w := csv.NewWriter(newFile)
		w.WriteAll(data)
		w.Flush()
		return filename, err
	}
}
